package com.hb.trade.server.center.sys.manager.news;

import cn.hutool.core.collection.CollUtil;
import com.hb.core.pojo.center.sys.dto.NewsCenterDTO;
import com.hb.core.pojo.center.sys.entity.NewsCenter;
import com.hb.core.pojo.enums.NewsTypeTwoEnum;
import com.hb.trade.server.center.sys.manager.NewsCenterManager;
import com.hb.trade.server.center.sys.service.NewsCenterService;
import lombok.extern.slf4j.Slf4j;
import org.fzzn.core.model.enums.LogicEnum;
import org.fzzn.core.util.Enums;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * describe:
 * 异议质疑
 * @author zhongdl
 * @date 2022/02/18
 */
@Service
@Slf4j
public class NewsCenterObjectionQuestion implements NewsCenterSava{

    protected final NewsCenterService newsCenterService;

    public NewsCenterObjectionQuestion(NewsCenterService newsCenterService) {
        this.newsCenterService = newsCenterService;
    }
    @Override
    public boolean insertNewsCenter(NewsCenterManager newsCenterManager) {
        log.info(">>>异议质疑",newsCenterManager);

        //替换模板
        String templateName = newsCenterManager.replaceTemplate();
        //投标人的审核状态
        if (Enums.equals(NewsTypeTwoEnum.BIDDER_EXPENSE_AUDIT,newsCenterManager.getNewsTypeTwo())){
            templateName = templateName.contains("被驳回") ? (templateName + "请修改后重新提交审核") :templateName;
        }
        List<Long> receiverIds = newsCenterManager.getReceiverIds();
        List<NewsCenter> newsCenterList = CollUtil.list(false);
        //组装接收人的消息记录
        for (Long receiverId : receiverIds) {
            NewsCenter newsCenter = newsCenterManager.to(NewsCenter.class);
            newsCenter.buildBaseData(1);
            newsCenter.setReceiverId(receiverId);
            newsCenter.setReadFlag(LogicEnum.NO.getCode());
            newsCenter.setTitle(templateName);
            newsCenterList.add(newsCenter);
        }
        return newsCenterService.saveBatch(newsCenterList);
    }
}
